package test;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Students implements Serializable{
    private int id;
    private String name;
    private int age;
    private double grade;
	public Students(int id, String name, int age,double grade) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
		this.grade = grade;
	}

	public int getId() {
		return id;
	}

	public double getGrade() {
		return grade;
	}

	public void setGrade(double grade) {
		this.grade = grade;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String toString() {
		return "Students [id=" + id + ", name=" + name + ", age=" + age + ", grade=" + grade + "]";
	}
    
}
public class Main {
	public static void main(String args[]) throws  IOException
	{
       FileOutputStream fos = new FileOutputStream("d:/stu.txt");
       DataOutputStream stu = new DataOutputStream (fos);
       Students[] student = new Students[3]; 
       student[0] = new Students(0, "Herry",20,92);
       student[1] = new Students(1, "Judy", 19,85);
       student[2] = new Students(2, "Jane", 21,78);
        try
        {
        	for (int i = 0; i < student.length; i++) {
        		stu.writeInt(student[i].getId());
                stu.writeUTF(student[i].getName());
                stu.writeInt(student[i].getAge());
                stu.writeDouble(student[i].getGrade());
			}
        }
        finally
        {
            stu.close();
        }
        FileInputStream  fis = new FileInputStream("d:/stu.txt");
		DataInputStream dis = new DataInputStream(fis);
		try
		{
			for (int i = 0; i < student.length; i++) {
				System.out.print(+dis.readInt());
			    System.out.print("\t "+dis.readUTF());
			    System.out.print("\t "+dis.readInt());
			    System.out.println("\t "+dis.readDouble());
			}
		}
		finally
		{
		    dis.close();
		}
		
    }
}
